package com.redis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

/**
 * 创建自己的 RedisTemplate
 * @Author: bowen
 * @Date: 2021/12/15 21:15
 */
@Configuration
public class RedisConfig {
    @Bean
    public StringRedisTemplate getTemplate(RedisConnectionFactory fc) {
        StringRedisTemplate tp = new StringRedisTemplate(fc);
        tp.setHashValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));

        return tp;
    }


}
